﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using nspLable.Function.Systems;
using nspLable.Function;
using Product;
using nspLable.Manage;
using nspJob;
using System.Text;

public partial class job_JobShow : System.Web.UI.Page
{
    public string _headstr = "";
    public string _typelike = "";
    public string _footstr = "";
    public string comCount1 = "0";
    public string comCount2 = "0";
    public string comCount3 = "0";
    public int sid = 0;
    public TJob tjb = new TJob();
    public TUser tus = new TUser();
    public string jobtypeStr = "";
    public DataTable typelistTab = new DataTable();
    public string age = "";
    public string readcookies = "";
    public string readjoblist = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (HttpContext.Current.Request.QueryString["id"] != null && HttpContext.Current.Request.QueryString["id"] != "")
            {
                sid = Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
            }
            Bind();
            getFoot();
            getHead();
            readjoblist = Base.BasePage.GetCookie("readjob") + sid + ",";
            //.GetCookie("shopcar") + gd + "," + productid + "," + buynum + "," + attri + ",0|";
            if(Base.BasePage.GetCookie("readjob")==null|| !Base.BasePage.GetCookie("readjob").ToString().Contains(sid.ToString()))
            {
                WriteCookie("readjob", readjoblist);   
            }
           // AddCookie();
            readcookies = readcookie();   
        }
        
    }
    private void Bind()
    {
        Rjob rjb = new Rjob();
        tjb = rjb.GateItem(sid);
        if (tjb == null)
        {
            Response.Redirect(Base.BasePage.Config.WebURL + "job/jobtrade" + Base.BasePage.Config.Rewrite + "?type=1");
        }
        RUser rus = new RUser();
        if(tjb!=null)
        {
            tus = rus.GateItem(tjb.UserID);    
        }
        typelistTab = rjb.GetJobType();
        comCount1 = rjb.GetcompanyCount("").Rows.Count.ToString();
        comCount2 = rjb.GetcompanyCount(" Verify=1 ").Rows.Count.ToString();
        comCount3 = rjb.GetcompanyCount(" (datediff(dd,RegDate,getdate()))=0 ").Rows.Count.ToString();
        
    }
    private void getHead()
    {
        TUserLable Temp = new RUserLable().GateItem("WS_整站头部");
        if (Temp.Info == null || Temp.Info == "")
            _headstr = "";
        else
            _headstr = Temp.Info.ToString();
        _headstr = _headstr.Replace("{PB_WebURL}", Base.BasePage.Config.WebURL);
        _headstr = _headstr.Replace("{PB_收录企业}", comCount1);
        _headstr = _headstr.Replace("{PB_审核通过企业}", comCount2);
        _headstr = _headstr.Replace("{PB_今日收录}", comCount3);
    }
    private void getFoot()
    {
        TUserLable Temp = new RUserLable().GateItem("WS_整站底部");
        if (Temp.Info == null || Temp.Info == "")
            _footstr = "";
        else
            _footstr = Temp.Info.ToString();
        _footstr = _footstr.Replace("{PB_WebURL}", Base.BasePage.Config.WebURL);

    }

    /// <summary>
    /// 写网站cookie值
    /// </summary>
    /// <param name="strName">项</param>
    /// <param name="strValue">值</param>
    private void WriteCookie(string strName, string strValue)
    {
        HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
        if (cookie == null)
        {
            cookie = new HttpCookie(strName);
        }
        cookie.Value = strValue;
        cookie.Expires = DateTime.Now.AddMinutes(2400);
        HttpContext.Current.Response.AppendCookie(cookie);
    }

    //最新浏览过的招聘信息
    protected string readcookie()
    {
        StringBuilder sb = new StringBuilder();
        if (Base.BasePage.GetCookie("readjob") != null)
        {
            string minolist = Base.BasePage.GetCookie("readjob").ToString();
            if (minolist != "")
            {
                string[] minojob = minolist.Split(',');
                int cnt = 0;
                for (int i = minojob.Length-1; i >= 0; i--)
                {
                    if(Base.Common.CheckNum(minojob[i].ToString()))
                    {

                        Rjob rjb = new Rjob();
                        tjb = rjb.GateItem(int.Parse(minojob[i], 0));
                        if (tjb != null)
                        {
                            sb.Append("<li>▪&nbsp;<a title=\"\" target=\"_blank\" href=\"" + Base.BasePage.Config.WebURL + "JobShow-" + int.Parse(minojob[i]) + Base.BasePage.Config.Rewrite + "\">" + Function.GetString(tjb.Position, 15) + "</a></li>");
                        }
                        if (cnt >= 10) break;
                    }
                    
                }
            }
        }
        return sb.ToString();
    }
}
